package algorithm.swordoff;

/**
 * 股票的最大利润
 */

public class SQ63 {

    public int maxProfit(int[] nums) {
        if (nums.length == 0 || nums.length == 1) return 0;

        int minHistory = nums[0];
        int maxProfit = 0;

        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > minHistory) maxProfit = Math.max(maxProfit, nums[i]-minHistory);
            minHistory = Math.min(minHistory, nums[i]);
        }

        return maxProfit;
    }

    public static void main(String[] args) {
        int[] a = {9,11,8,5,7,12,16,14};
        int[] b = {1,1,1};
        SQ63 sst = new SQ63();
        System.out.println(sst.maxProfit(b));
    }
}
